import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const tokenStore = defineStore('token', () => {
  const token = ref(null)
  const tokenStr = computed(() => token.value)
  function updateToken(tk) {
    token.value = tk
  }
  // 重置token
  function $reset() {
    token.value = null
  }

  return { token, tokenStr, updateToken, $reset }
}, {
  persist: {
    key: 'token', //存储名称
    storage: sessionStorage, // 存储方式
  }
})
